import { UserProfilesAPI } from "@/request/Api"
export default {
    namespaced: true,
    state: {
        cartTotal: 0,
        userInfo: {
            headImg: require("../../assets/img/service.848ec511.png"),
            nickName: "昵称",
            coin: "999"
        }
    },
    mutations: {
        // 修改用户信息
        updateUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal;
            state.userInfo = payload.userInfo
        },

        // 用户信息初始化
        initUserInfo(state) {
            state.cartTotal = 0;
            state.userInfo = {
                headImg: require("../../assets/img/service.848ec511.png"),
                nickName: "昵称",
                coin: "999"
            }
        }
    },
    actions: {
        async asyncChangeUserInfo({ commit }, payload) {
            let res = await UserProfilesAPI();
            console.log("用户信息", res);
            // 更新vuex的用户信息
            commit('updateUserInfo', res.data)
        }
    }

}